package com.yanqu.road.entity.config.goods;

import com.yanqu.road.utils.date.DateHelper;

import java.util.HashSet;
import java.util.Set;

public class WasheReplaceBoxData {

    private int activityId;

    private int type;

    private int chooseMallId;

    private long lastUpdateTime;

    private Set<Integer> allMallIdSet = new HashSet<>();

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getChooseMallId() {
        return chooseMallId;
    }

    public void setChooseMallId(int chooseMallId) {
        this.chooseMallId = chooseMallId;
    }

    public long getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(long lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public Set<Integer> getAllMallIdSet() {
        return allMallIdSet;
    }

    public void setAllMallIdSet(Set<Integer> allMallIdSet) {
        this.allMallIdSet = allMallIdSet;
    }

    /**
     * 检测时间是否要从allMallIdSet中随机出一个mallId
     */
    public void checkRandomMallId() {
        long now = System.currentTimeMillis() / 1000;
        // 如果随机出来的东西是今天的 不为0 并且在所有mallId中 就不用再随机了
        if (DateHelper.isSameDay(now, lastUpdateTime) && chooseMallId != 0 && allMallIdSet.contains(chooseMallId)) {
            return;
        }
        lastUpdateTime = now;
        if (allMallIdSet == null || allMallIdSet.isEmpty()) {
            return;
        }
        int size = allMallIdSet.size();
        int index = (int) (Math.random() * size);
        int i = 0;
        for (Integer mallId : allMallIdSet) {
            if (i == index) {
                chooseMallId = mallId;
            }
            i++;
        }
    }
}
